/**
 * 
 */
package com.paypal.melearning.ui;

import com.vaadin.terminal.ClassResource;
import com.vaadin.terminal.Resource;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;


/**
 * @author prakrishnan
 * 
 */
public class HeaderPannel extends VerticalLayout {

	private Panel curWindow;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public HeaderPannel(Panel windowPanel) {
		curWindow = windowPanel;
	}

	@Override
	public void attach() {
		// TODO Auto-generated method stub
		super.attach();
		
		setSpacing(false);
		setMargin(false);
		
		
		final GridLayout header = new GridLayout(3, 1);
		header.setWidth("100%");
		header.setHeight("20%");
		header.setSpacing(false);
		
		addComponent(header);
		
		Component search = getSearchTool();
		header.addComponent(search);
//		header.setComponentAlignment(search, Alignment.TOP_LEFT);
		
		Component title = getTitle();
		header.addComponent(title);
//		header.setComponentAlignment(search, Alignment.TOP_CENTER);
		
		Component user = getUserOptions();
		header.addComponent(user);
//		header.setComponentAlignment(search, Alignment.TOP_RIGHT);

	
	}

	private Component getUserOptions() {
		HorizontalLayout userPannel = new HorizontalLayout();
		userPannel.setSizeFull();

		userPannel.addComponent(new AddPinUI(curWindow));
		userPannel.addComponent(new Label("Login"));

		return userPannel;
	}

	private Component getTitle() {
/*		VerticalLayout title = new VerticalLayout();
		Resource logoIcon = new ClassResource("/logo.jpg", getApplication());
		Embedded logo = new Embedded("",logoIcon);
		logo.setHeight("100%");
		title.addComponent(logo);*/
		
		Label title = new Label("<h1>Me Learning</h1>",
                Label.CONTENT_XHTML);
		return title;
	}

	private Component getSearchTool() {
		HorizontalLayout searchBar = new HorizontalLayout();
		TextField searchBox = new TextField();
		searchBox.setInputPrompt("Search");
		searchBar.addComponent(searchBox);
		Resource srchIcon = new ClassResource("/search-icon.jpg", getApplication());
//		searchBar.setIcon(srchIcon);
		Button searchButton = new Button();
		searchButton.setIcon(srchIcon);
		searchButton.setHeight("10px");
		searchButton.setWidth("20px");
		searchBar.addComponent(searchButton);
		
		return searchBar;
	}
}
